/*
 * @Author: Cong.z 
 * @Date: 2024-05-28 16:35:08
 * @Last Modified by: Cong.z
 * @Last Modified time: 2024-05-28 16:43:19
 * @Detail: hk camera driver
 * @Change Log:first create
 */
#pragma once
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <functional>
#include "MvCameraControl.h"
#include <thread>

enum camera_status{
    DEV_INIT = 0,
    DEV_CONNECT,
    DEV_RUNING,
    DEV_DISCONNECT,
    DEV_NULL
};


//==========================================
// 相机打开控制流程：
// 1、查找设备
// 2、打开设备
// 3、打开grabbing
//==========================================
class hk_camera
{
private:
    /* data */
    void* cam_handle_;   //cam handle
    MV_CC_DEVICE_INFO* dev_info_;   //dev info
    camera_status status_;
    bool is_open_;
    bool is_grabbing_;
    std::shared_ptr<std::thread> cap_thread_;
    bool cap_thread_flag_;
    std::function<void(int height, int width, unsigned char* data)> cam_callback_;


    bool cameraInit();
    bool cameraFindDev();
    bool cameraOpenDev();
    bool cameraCloseDev();
    bool cameraParamSet();
    bool cameraStartGrabbing();
    bool cameraStopGrabbing();
    bool printDeviceInfo(MV_CC_DEVICE_INFO* pstMVDevInfo);
    void capData(void *pUser);
public:
    hk_camera(/* args */);
    ~hk_camera();
    bool start();
    bool stop();
    void regCallBack(std::function<void(int height, int width, unsigned char* data)> call){
        cam_callback_ = call;
    }
};

